package com.company.jdbc;

import java.sql.*;
        import java.util.ResourceBundle;

public class jdbcutils {
    private  static  String  driver = null;
    private  static  String   url = null;
    private  static  String    username = null;
    private  static  String    password = null;
    private  static Connection conn  = null;
    static {
        ResourceBundle rb = ResourceBundle.getBundle("jdbc");
        driver = rb.getString("jdbc.driver");
        url = rb.getString("jdbc.url");
        password = rb.getString("jdbc.password");
        username = rb.getString("jdbc.username");
        try {
            Class.forName(driver);
            conn = DriverManager.getConnection(url, username, password);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }


    }
    public static Connection getConnection () {
        return conn;

    }
    public static void close(ResultSet rs, Statement sm, Connection con){
        if (rs != null) {
            try {
                rs.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

        if (sm != null) {
            try {
                sm.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

        if (con != null) {
            try {
                con.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }

}
